<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
    <% String path=request.getContextPath(); String basePath=request.getScheme() + "://" + request.getServerName() + ":"
        + request.getServerPort() + path + "/" ; %>

        <!DOCTYPE html>
        <html>

        <head>
            <base href="<%=basePath%>">

            <title>移动端首页</title>
        </head>

        <body>
            <script src="<%=basePath%>resourse/weui/lib/jquery-2.1.4.js"></script>
            <script>
                $(function () {
                    getCode();
                    // login('HI5272');
                })

                function getCode() {
                    var code = getQueryVariable('code');//人员编码
                    if (!code) {
                        return;
                    }
                    $.ajax({
                        type: "post",
                        url: "wx/getHI",
                        async: false,
                        data: {
                            code: code
                        },
                        success: function (data) {
                            login(data);
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert('消息', errorThrown);
                        }
                    });
                }

                function login(HI) {
                    var url = getQueryVariable('url');
                    $.ajax({
                        type: "post",
                        url: "api/loginMobile",
                        dataType: "json",
                        data: {
                            hi: HI
                        },
                        success: function (data) {
                            if (data.code == 60200) {
                                localStorage.setItem("token", data.data.tokenString);
                                localStorage.setItem("sysUser", JSON.stringify(data.data.sysUser));
                                if (url) {
                                    window.location.href = "<%=basePath%>wx/" + url + "?userid=" + data.data.sysUser.userid;
                                } else {
                                    alert('url不存在!')
                                }

                            } else {
                                alert('用户名或密码不正确');
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert('消息', errorThrown);
                        }
                    });
                }


                //获取访问参数id
                function getQueryVariable(variable) {
                    var query = window.location.search.substring(1);
                    var vars = query.split("&");
                    for (var i = 0; i < vars.length; i++) {
                        var pair = vars[i].split("=");
                        if (pair[0] == variable) {
                            return pair[1];
                        }
                    }
                    return (false);
                }
            </script>
        </body>

        </html>